﻿using SeeSharpTools.JY.DSP.Utility;
using SeeSharpTools.JY.File;
using Sunny.UI;
using System;
using System.IO;

namespace SeeSharpTools.Demo
{
    public partial class FormDetrend : UIPage
    {
        public FormDetrend()
        {
            InitializeComponent();
        }

        private void FormDetrend_Load(object sender, EventArgs e)
        {
            DirectoryInfo directory = new DirectoryInfo(Environment.CurrentDirectory);
            string path = directory.Parent.Parent.FullName + "\\ExampleData" + "\\Waveform" + "\\ecg.csv";
            double sampleRate = 800;
            double[,] data = CsvHandler.Read<double>(path);
            double[] x = new double[data.GetLength(0)];
            for (int i = 0; i < data.GetLength(0); i++)
            {
                x[i] = data[i, 0];
            }

            SignalOperation.Analog.Detrend(x, out double[] y, out double[] trend, DetrendMethod.Polynomial, 3);
            easyChartX1.Plot(x, 0, 1 / sampleRate);
            easyChartX2.Plot(y, 0, 1 / sampleRate);
        }
    }
}